package com.example.homework.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.homework.db.tables.Photos
import com.example.homework.repositories.PhotoRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

class PhotoViewModel(val repository: PhotoRepository):ViewModel() {
    val photos:Flow<List<Photos>> = repository.photos.stateIn(
        scope = viewModelScope,
        started = SharingStarted.WhileSubscribed(5000L),
        initialValue = listOf()
    )

    fun addPhoto(photos: Photos){
        viewModelScope.launch {
            repository.addPhoto(photos)
        }
    }
}